export function initalToken(token) {
	// 小程序端默认登录
	if (token) {
		this.$aplsjsonheader = {
			token: token,
			"content-Type": "application/json",
		};
		this.$aplsFormDataheader = {
			token: token,
			"content-Type": "application/form-data",
		}
	}
}

export function resetToken() {
	uni.removeStorage({
		key: "token",
	});
	console.log('resetToken',uni.getStorageSync("token"))
	this.$aplsjsonheader = {
		token: "",
		"content-Type": "application/json",
	};
	this.$aplsFormDataheader = {
		token: "",
		"content-Type": "application/form-data",
	}
}
export function varitfyToken() {
	if (!this.$store.state.token || this.$store.state.userInfo == undefined) {
		return false;
	}
	return true;
}
export function updateToken(token) {
	uni.setStorage({
		key: 'token',
		data: token,
	});
	this.$aplsjsonheader = {
		token: token,
		"content-Type": "application/json",
	};
	this.$aplsFormDataheader = {
		token: token,
		"content-Type": "application/form-data",
	}
}

export function errMessageToast(errMsg) {
	uni.showToast({
		title: errMsg,
		duration: 1000,
		icon: "none",
	});
}
export function removeStorage(key) {
	uni.removeStorage({
		key: key,
	});
}
export function saveStorage(key, value) {
	console.log(key, value);
	uni.setStorage({
		key: key,
		data: value,
	});
}
export function getToken() {
	return new Promise((resolve, reject) => {
		uni.getStorage({
			key: "token",
			success: (res) => {
				if (res.data == "" || res.data == undefined) {
					reject();
				} else {
					resolve(res.data);
				}
			},
			fail: (err) => {
				console.log(err);
				reject();
			},
		});
	});
}
